home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Macintosh / Development & Resource Tools / MacsBug6.5.3.sit / MacsBug 6.5.3 / Building dcmds / C Samples / Vol.c < prev    next >
Text File  |  1996-02-22  |  5KB  |  224 lines

  1. /*
  2.     File:        Vol.c
  3.  
  4.     Contains:    A dcmd which dumps all volumes from the VCB queue.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglas
  9.  
  10.     Copyright:    © 1988,1993-1994, 1996 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <6>   25-Jan-96    JM3        Updated the sample build commands to be current. Took out lowmem
  15.                                     define and included LowMem.h.
  16.          <5>   11-Dec-94    JM3        Updated for new version 3 dcmd requirements.
  17.          <4>   24-Jan-94    JM3        EqualString is now in TextUtils.h with the Universal Interfaces.
  18.          <2>     9/10/93    DAL        Fixed volume-name matching to work again (was using
  19.                                     non-prototyped "EQUALSTRING" instead of EqualString).  Widened
  20.                                     the volume-name column.  Changed "VCB at" to "VCB addr" and made
  21.                                     it align for 32-bit addresses.
  22.  
  23.     Modification history:
  24.         29Nov88 sad        revised for new dcmd names.  display more info.
  25.          5Oct88 sad        written.
  26.  
  27.     The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
  28.     in the System folder. The dcmd's name in MacsBug will be the name of the file built by
  29.     the Linker.
  30.  
  31.     C Vol.c
  32.     Link -o Vol -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Put.c.o Vol.c.o" ∂
  33.         "{Libraries}Runtime.o" "{Libraries}Interface.o"
  34.     BuildDcmd Vol 198 -format3
  35.     Echo 'include "Vol";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  36.  
  37. */
  38.  
  39. #include <Types.h>
  40. #include <Memory.h>
  41. #include <OSUtils.h>
  42. #include <Files.h>
  43. #include <TextUtils.h>
  44. #include <LowMem.h>
  45.  
  46. #include "dcmd.h"
  47. #include "put.h"
  48.  
  49. static void DrawHdr()
  50. {
  51. //                             1         2         3         4         5         6         7
  52. //                    1234567890123456789012345678901234567890123456789012345678901234567890123456789
  53.     dcmdDrawLine("\pvRef Vol                  Flg dRef Drive FSID #Blk BlkSiz #Files #Dirs  Blsd Dir VCB addr");
  54.  
  55. }
  56.  
  57.  
  58. static void DrawVCB(VCB* vcbp)
  59. {
  60.  
  61.     PutUHexWord(vcbp->vcbVRefNum);
  62.     PutSpace();
  63.     PutPStrTruncTo(vcbp->vcbVN,15+10);
  64.     PutSpace();
  65.     PutChar((vcbp->vcbFlags & 0x8000) ? 'D' : 'd');
  66.     PutChar((vcbp->vcbAtrb & 0x8000) ? 'S' : 's');
  67.     PutChar((vcbp->vcbAtrb & 0x4000) ? 'H' : 'h');
  68.     PutSpace();
  69.     PutUHexWord(vcbp->vcbDRefNum);
  70.     PutSpace();
  71.     PutSpace();
  72.     PutUHexWord(vcbp->vcbDrvNum);
  73.     PutSpace();
  74.     PutUHexWord(vcbp->vcbFSID);
  75.     PutSpace();
  76.     PutUHexWord(vcbp->vcbNmAlBlks);
  77.     PutSpace();
  78.     PutUHexZTo(vcbp->vcbAlBlkSiz,6,47+10);
  79.     PutSpace();
  80.     PutUHexZTo(vcbp->vcbFilCnt,6,54+10);
  81.     PutSpace();
  82.     PutUHexZTo(vcbp->vcbDirCnt,6,61+10);
  83.     PutSpace();
  84.     PutUHexZTo(vcbp->vcbFndrInfo[0],6,70+10);
  85.     PutSpace();
  86.     PutUHexZTo((unsigned long)vcbp,8,77+10);
  87.     PutLine();
  88.  
  89. }
  90.  
  91.  
  92. // PrefixPStr
  93. //
  94. // Returns true if astr is equal to a prefix of bstr.
  95. // astr must not be longer than 31 characters.
  96.  
  97. static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
  98. {
  99.  
  100.     char newstr[32];
  101.     int alen = *astr;
  102.     int blen = *bstr;
  103.  
  104.     if (alen <= blen)
  105.     {
  106.         BlockMove(bstr+1,newstr+1,alen);
  107.         newstr[0] = alen;
  108.         return EqualString(astr,newstr,false,true);
  109.     }
  110.  
  111.     return false;    
  112.  
  113. }
  114.  
  115.  
  116.  
  117. pascal void CommandEntry(dcmdBlock* paramPtr)
  118. {
  119.  
  120.     static const char usageStr[] = "\p[vRefNum|drvNum|\"vol name\"]";
  121.  
  122.     switch (paramPtr->request)
  123.     {
  124.         case dcmdInit:
  125.             break;
  126.  
  127.         case dcmdHelp:
  128.             dcmdDrawLine("\pDisplays volume information for the given vrefnum, volume name or all");
  129.             dcmdDrawLine("\pmounted volumes. Flags are D/d=Dirty, S/s=Software locked,");
  130.             dcmdDrawLine("\pH/h=Hardware locked.");
  131.             break;
  132.  
  133.         case dcmdGetInfo:
  134.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  135.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  136.             break;
  137.  
  138.         case dcmdDoIt:
  139.         {
  140.             Boolean    doOneVCB = false;
  141.             long    vref;
  142.             short    c;
  143.             Boolean    haveVolName = false;
  144.             Str255    volname;
  145.             VCB*    vcbp;
  146.             int        numvcbs = 0;
  147.             Boolean    foundOne = false;
  148.  
  149.             dcmdSwapWorlds();
  150.  
  151.             dcmdDrawLine("\pDisplaying Volume Control Blocks");
  152.  
  153.             // get low-memory values after dcmdSwapWorlds()
  154.             vcbp = (VCB*) (LMGetVCBQHdr()->qHead);
  155.  
  156.             c = dcmdPeekAtNextChar();
  157.             if (c == '"' || c == '\'')
  158.             {
  159.                 haveVolName = true;
  160.                 (void) dcmdGetNextParameter(volname);
  161.             }
  162.             else
  163.                 (void) dcmdGetNextExpression(&vref, &doOneVCB);
  164.  
  165.             if (doOneVCB)
  166.                 vref = (short) vref;
  167.  
  168.             while (vcbp)
  169.             {
  170.                 if ((doOneVCB && (vcbp->vcbVRefNum == vref || vcbp->vcbDrvNum == vref)) ||
  171.                     (haveVolName && PrefixPStr(volname,vcbp->vcbVN)) ||
  172.                     (!doOneVCB && !haveVolName))
  173.                 {
  174.                     numvcbs++;
  175.                     if (!foundOne)
  176.                     {
  177.                         DrawHdr();
  178.                         foundOne = true;
  179.                     }
  180.                     DrawVCB(vcbp);
  181.                 }
  182.                 if (paramPtr->aborted) break;
  183.                 if (vcbp->qLink == 0)
  184.                     if (vcbp != (VCB*)(LMGetVCBQHdr()->qTail))
  185.                         dcmdDrawLine("\pVCB queue does not end at VCBQHdr.qTail");
  186.                 vcbp = (VCB*)vcbp->qLink;
  187.             }
  188.             if (!paramPtr->aborted)
  189.                 if (haveVolName || doOneVCB)
  190.                 {
  191.                     if (!foundOne)
  192.                         if (haveVolName)
  193.                         {
  194.                             PutPStr("\pNo mounted volumes match \"");
  195.                             PutPStr(volname);
  196.                             PutChar('"');
  197.                             PutLine();
  198.                         }
  199.                         else
  200.                         {
  201.                             PutPStr("\pNo mounted volumes match ");
  202.                             PutUHexWord(vref);
  203.                             PutLine();
  204.                         }
  205.                 }
  206.                 else
  207.                 {
  208.                     PutUDec(numvcbs);
  209.                     PutPStr("\p VCBs");
  210.                     PutLine();
  211.                 }
  212.  
  213.             dcmdSwapWorlds();
  214.             break;
  215.         }
  216.  
  217.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  218.  
  219.         default:
  220.             break;
  221.     }
  222.  
  223. } // CommandEntry
  224.